<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加流程</title>
    <link rel="icon" href="${pageContext.request.contextPath}/lib/static/login/images/favicon.ico">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/lib/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<div class="layui-fluid">
    <hr class="layui-bg-red">
    <div class="layui-row">
        <div class="layui-col-sm9  layui-col-sm-offset1">
            <form class="layui-form layui-form-pane" lay-filter="ProcedureEdit">
                <input type="hidden" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <input type="text" name="type" lay-verify="title" autocomplete="off" placeholder="请输入类型" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        <input type="hidden" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">申请人</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入申请人" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">所在部门</label>
                    <div class="layui-input-block">
                        <input type="text" name="dept" lay-verify="title" autocomplete="off" placeholder="请输入所在部门" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">申请内容</label>
                    <div class="layui-input-block">
                        <textarea name="context" placeholder="请输入内容" class="layui-textarea note"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-col-sm-offset3" >
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="saveProcedure">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    var baseUrl = '${pageContext.request.contextPath}/procedure/';

    /*发送ajax请求访问后台*/
    function sendAjaxPostReq($, param, method) {
        $.post(
            baseUrl + method,
            param,
            function (result) {
                if (result.code == 0) {
                    layer.msg(result.msg, {icon: 1, time: 500}, function () {
                        parent.window.location.reload();
                    });
                } else {
                    layer.msg(result.msg, {icon: 5, anim: 6});
                }
            },
            "json"
        );
    }

    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.$;

        /*表单提交*/
        form.on('submit(saveProcedure)', function (data) {
            sendAjaxPostReq($, data.field, "addProcedure");
            return false;
        });

        /*表单提交 修改*/
        form.on('submit(editProcedure)', function (data) {
            sendAjaxPostReq($, data.field, "updateProcedure");
            return false;
        });
    });
</script>
</body>
</html>
